const http = require('http')
const url=require('url');
const server = http.createServer()
const PI=3.1415926;
var circle={r:4,area:function () {return PI*this.r*this.r},permitter:function () {return 2*PI*this.r}}
server.on('request', (req, res) => {
    console.log(req.url);
    res.setHeader('Content-Type', 'text/html; charset=utf-8')
    // let slice = url.slice('?');
    // var need=slice[1];
    var rurl=req.url;
    var ret="";
    if(rurl=='/'||!rurl.includes('?')){
        ret+="<h1>请输入路径</h1>";
        console.log(ret);
        res.end(ret);
    }else {
        var parse = url.parse(rurl);
        var query = parse.query;
         console.log(query);
         let split = query.split("=");
        ret+=split[0]+".";
        ret+=split[1]+"()";
        console.log(ret);
        res.end(eval(ret));
    }

    // if(1){
    //     for (const sElement of need.slice('&')) {
    //         method+=sElement+'.';
    //     };
    //     method-='.';
    // }else {
    //     method="<请输入正确路径>";
    // }



})
server.listen(8090, () => {
    console.log('server running at http://127.0.0.1:8090')
})
